﻿
namespace Calendar
{
    internal class Program
    {
        /// <summary>
        /// Calendar of 2022
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            DateTime date = new DateTime(2022, 1, 1);
            int month = 0;
            while (date.Year==2022)
            {//打印每月开头
                int dayofweek1 = Convert.ToInt32(date.DayOfWeek);
                int day1 = date.Day;
                int x0 = (month%3)*40, y0 = (month/3)*10;
                Console.SetCursorPosition(x0, y0);
                month++;
                Console.WriteLine("           {0}月       ", month);
                Console.SetCursorPosition(x0, y0+1);
                Console.WriteLine("日  一  二  三  四  五  六");
                //确定1号位置
                Console.SetCursorPosition(x0, y0+2);
                Console.Write(new String(' ', dayofweek1*4));
                Console.Write(day1);
                //打印其他日期
                int weekn = 0;
                while (date.Month==month)
                {
                    date=date.AddDays(1);
                    int DAYOFWEEKn = Convert.ToInt32(date.DayOfWeek);
                    int DAYn = date.Day;
                    if (DAYn==1) break;
                    //根据1号周几确定其他日期在第几行开始
                    if (dayofweek1==6)
                    {
                        Console.SetCursorPosition(DAYOFWEEKn*4+x0, weekn+3+y0);
                        Console.Write(DAYn);
                    }
                    else
                    {
                        Console.SetCursorPosition(DAYOFWEEKn*4+x0, weekn+2+y0);
                        Console.Write(DAYn);
                    }
                    if (DAYOFWEEKn==6)
                        weekn++;
                }
            }Console.SetCursorPosition(0, 40);
        }

    }
}























